Skip to content

feat: Add OpenAPI Support to chat.postMessage API#36090

Draft
ahmed-n-abdeltwab wants to merge 3 commits intoRocketChat:developfrom
ahmed-n-abdeltwab:feat/openapi-chat-postMessage
Draft

feat: Add OpenAPI Support to chat.postMessage API#36090
ahmed-n-abdeltwab wants to merge 3 commits intoRocketChat:developfrom
ahmed-n-abdeltwab:feat/openapi-chat-postMessage

Conversation

@ahmed-n-abdeltwab
Copy link
Copy Markdown
Contributor

@ahmed-n-abdeltwab ahmed-n-abdeltwab commented May 27, 2025

Description:
This PR integrates OpenAPI support into the Rocket.Chat API, migrate of Rocket.Chat API endpoints to the new OpenAPI pattern. The update includes improved API documentation, enhanced type safety, and response validation using AJV.

Key Changes:

  • Implemented the new pattern and added AJV-based JSON schema validation for API.
  • Uses the ExtractRoutesFromAPI utility from the TypeScript definitions to dynamically derive the routes from the endpoint specifications.
  • Enabled Swagger UI integration for this API.
  • This does not introduce any breaking changes to the endpoint logic.

Issue Reference:
Relates to #34983, part of the ongoing OpenAPI integration effort.

Testing:

  • Verified that the API response schemas are correctly documented in Swagger UI.
  • All tests passed without any breaking changes
$ yarn testapi -f '[Users]'

  [Chat]
    /chat.postMessage
      ✔ should throw an error when at least one of required parameters(channel, roomId) is not sent
      ✔ should throw an error when it has some properties with the wrong type(attachments.title_link_download, attachments.fields, message_link) (86ms)
      ✔ should throw an error when the properties (attachments.fields.title, attachments.fields.value) are with the wrong type
      ✔ should return statusCode 200 when postMessage successfully (417ms)
      should throw an error when the sensitive properties contain malicious XSS values
        ✔ attachment.message_link
        ✔ attachment.author_link
        ✔ attachment.title_link
        ✔ attachment.action.url
        ✔ message.avatar
        ✔ attachment.action.image_url
        ✔ attachment.thumb_url
        ✔ attachment.author_icon
        ✔ attachment.image_url
        ✔ attachment.audio_url
        ✔ attachment.video_url
      text message allowed size
        ✔ should return an error if text parameter surpasses the maximum allowed size (50ms)
        ✔ should return an error if text parameter in the first attachment surpasses the maximum allowed size (45ms)
        ✔ should return an error if text parameter in any of the attachments surpasses the maximum allowed size
        ✔ should pass if any text parameter length does not surpasses the maximum allowed size (77ms)
    ***
    ***
    
  168 passing (23s)
  2 pending

Endpoints:

Looking forward to your feedback! 🚀

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented May 27, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented May 27, 2025

🦋 Changeset detected

Latest commit: dd24f9a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 41 packages
Name Type
@rocket.chat/meteor Minor
@rocket.chat/rest-typings Minor
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/http-router Patch
@rocket.chat/models Patch
@rocket.chat/ui-contexts Major
@rocket.chat/web-ui-registration Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/livechat Patch
@rocket.chat/mock-providers Patch
@rocket.chat/cron Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch
@rocket.chat/ui-client Major
@rocket.chat/media-calls Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/ui-avatar Major
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-voip Major
@rocket.chat/core-typings Minor
@rocket.chat/apps Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as ready for review June 3, 2025 13:02
@ahmed-n-abdeltwab ahmed-n-abdeltwab requested review from a team as code owners June 16, 2025 17:10
@ahmed-n-abdeltwab
Copy link
Copy Markdown
Contributor Author

Hey, @cardoso, the ChatPostMessageEndpoints write now return never, which makes the endpoints act like a base type itself, which makes a problem. So, #36246 needs to be merged first, and then ExtractRoutesFromAPI will not return never, and everything will run like magic, and the CI will not be angry.

export type ChatPostMessageEndpoints = ExtractRoutesFromAPI<typeof chatPostMessageEndpoints>;
// TODO: Need to remove the ChatEndpoints packages/rest-typings/src/index.ts file, but only after implementing all the endpoints.
declare module '@rocket.chat/rest-typings' {
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
interface Endpoints extends ChatPostMessageEndpoints {}
}

@ahmed-n-abdeltwab ahmed-n-abdeltwab force-pushed the feat/openapi-chat-postMessage branch from 372a6e6 to e336a45 Compare June 26, 2025 16:16
@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as draft July 11, 2025 14:11
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.69%. Comparing base (afaabea) to head (dd24f9a).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36090      +/-   ##
===========================================
+ Coverage    70.66%   70.69%   +0.02%     
===========================================
  Files         3191     3191              
  Lines       112965   112963       -2     
  Branches     20451    20464      +13     
===========================================
+ Hits         79829    79861      +32     
+ Misses       31088    31057      -31     
+ Partials      2048     2045       -3     
Flag Coverage Δ
unit 71.31% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ahmed-n-abdeltwab ahmed-n-abdeltwab marked this pull request as ready for review July 11, 2025 15:10
@ahmed-n-abdeltwab
Copy link
Copy Markdown
Contributor Author

@cardoso, I think this is going to work now. I tested it locally, and everything looks good.

@ahmed-n-abdeltwab
Copy link
Copy Markdown
Contributor Author

this pr need an update

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 27, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8b1f1df9-aeb8-4ffe-8cda-d8ff8e63f12f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…ndpoints

migrating to a modern chained route definition syntax and utilizing shared AJV schemas for validation to enhance API documentation and ensure type safety through response validation.
@ahmed-n-abdeltwab ahmed-n-abdeltwab force-pushed the feat/openapi-chat-postMessage branch from 303e3cc to 2e4fe2b Compare February 25, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants